package com.pasu.breakreminder.subservices;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.Context;

import com.pasu.breakreminder.utils.PreferencesHelper;

public class SubServicesManager {
    private Context mContext;
    private PreferencesHelper ph;
    private List<SubService> services;

    public SubServicesManager(Context context) {
        mContext = context;
        ph = new PreferencesHelper(mContext);
        services = new ArrayList<SubService>();
    }

    public void configureSubServices() {
        services.add(new SubServiceBroadcaster(mContext));
        boolean sound = ph.getBoolean(PreferencesHelper.Settings.Notification.ENABLE_SOUND);
        boolean vibra = ph.getBoolean(PreferencesHelper.Settings.Notification.ENABLE_VIBRATE);
        boolean led = ph.getBoolean(PreferencesHelper.Settings.Notification.ENABLE_LED);
        if (ph.getBoolean(PreferencesHelper.Settings.Notification.ENABLE_NOTIFICATIONS)) {
            services.add(new SubServiceNotifications(mContext, sound, vibra, led));
        } else {
            if (sound) {
                services.add(new SubServiceSound(mContext));
            }
            if (vibra) {
            }
        }
    }

    public void startSubServices() {
        for (Iterator<SubService> iterator = services.iterator(); iterator.hasNext();) {
            SubService service = iterator.next();
            service.startSubService();
        }
    }

    public void stopSubServices() {
        for (Iterator<SubService> iterator = services.iterator(); iterator.hasNext();) {
            SubService service = iterator.next();
            service.stopSubService();
        }
    }
}
